package com.study.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class LoginController {
    @PostMapping(value = "/login")
    public String login(@RequestParam("name")String name,
                        @RequestParam("pwd")String pwd,
                        Map<String,String> map,
                        HttpSession session){
        if(!StringUtils.isEmpty(name)&&"123456".equals(pwd)){
            session.setAttribute("loginuser",name);
            return "redirect:/main.html";
        }
        map.put("msg","登录失败");
        return "index";
    }
}
